package com.magic.smartcity.view.more.adapters

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import com.magic.smartcity.R
import com.magic.smartcity.beans.BusLineStopBean
import com.magic.smartcity.databinding.ItemBusDetailStationListBinding

/**
 * @description:
 * @create: Create by Magic on 2022/2/24.
 */
class BusLineDeatilStationListAdapter :
    RecyclerView.Adapter<BusLineDeatilStationListAdapter.ItemHolder>() {
    class ItemHolder(binding: ItemBusDetailStationListBinding) : RecyclerView.ViewHolder(binding.root) {
        val binding = binding
    }

    private val list: MutableList<BusLineStopBean> = mutableListOf()
    private val TAG: String = "BusLineDeatilStationListAdapter"
    fun setData(data: List<BusLineStopBean>) {
        list.clear()
        list.addAll(data)
        //将起始站数据重新更改一下
        list[0].name = "起点站: ${list[0].name}"
        list[list.size-1].name = "终点站: ${list[list.size-1].name}"
        notifyDataSetChanged()
    }

    override fun onCreateViewHolder(
        parent: ViewGroup,
        viewType: Int
    ): BusLineDeatilStationListAdapter.ItemHolder {
        val inflate = DataBindingUtil.inflate<ItemBusDetailStationListBinding>(
            LayoutInflater.from(parent.context),
            R.layout.item_bus_detail_station_list,
            parent,
            false
        )
        return ItemHolder(inflate)
    }

    override fun onBindViewHolder(
        holder: BusLineDeatilStationListAdapter.ItemHolder,
        position: Int
    ){
        holder.binding.stationDetail = list[position]
    }

    override fun getItemCount() = list.size
}